'''
Author: your name
Date: 2021-11-05 17:22:42
LastEditTime: 2021-11-12 10:12:10
LastEditors: Please set LastEditors
Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
FilePath: /tinyms/tinyms-api/apps/cms/link/service.py
'''
from app import db
from .model import Link

class LinkService():
    '''
    保存外部链接
    '''
    def save(link):
        db.session.add(link)
        db.session.commit()
    
    '''
    更新外部链接
    '''
    def update(link):
        tmp_link = Link.query.get(link.link_pk)
        tmp_link.link_title = link.link_title
        tmp_link.link_images =  link.link_images
        tmp_link.link_address = link.link_address
        tmp_link.link_remarks = link.link_remarks
        db.session.commit()
    
    '''
    删除数据
    '''
    def delete(link_pk):
        link = Link.query.get(link_pk)
        db.session.delete(link)
        db.session.commit()
    '''
    分页查询
    '''
    def pages(page):
        pages = Link.query.paginate(int(page), 30, False) #flask_sqlalchemy提供分页方法.paginate
        return pages